package br.com.BRisa.upnp;

import br.com.BRisa.upnp.upnp_default;
import br.com.BRisa.util.Log;
import br.com.BRisa.util.looping_call;


public class MSEARCH {
	
	
	static double DEFAULT_SEARCH_TIME = upnp_default.MSEARCH_DEFAULT_SEARCH_TIME;
    static String DEFAULT_SEARCH_TYPE = upnp_default.MSEARCH_DEFAULT_SEARCH_TYPE;
    static boolean ENABLE = false;
    static String _args = "a";
    
        static String msg_already_started = "tried to start() MSearch when already started";
        static String msg_already_stopped = "tried to stop() MSearch when already stopped";

	private int SearchMx = SSDP.DEFAULT_MSEARCH_MX;

	
	public MSEARCH(boolean start,double interval, String ssdp_addr, int ssdp_port){
    	start = true;
    	interval = DEFAULT_SEARCH_TIME; 
    	ssdp_addr = upnp_default.SSDP_ADDR;
        ssdp_port = upnp_default.SSDP_PORT;
    }

	
	public int getSearchMx()
	{
		return SearchMx;
	}

	public void setSearchMx(int ms) 
	{
		SearchMx = ms;
	}
    public static boolean isEnable(){
	   return ENABLE;
}
    //Start to search
    public static void Start(double interval, String Search_type ){
           interval = DEFAULT_SEARCH_TIME;
           Search_type = DEFAULT_SEARCH_TYPE;
           if (isEnable() == false){
        	   Sockets.open();
        	   _args = Search_type;
        	   looping_call.Start(interval, true);
        	   Log.Warning("M_Search Started");
           }else
        	   Log.Warning(msg_already_started);
    }
    public static void Stop(){
    	if(isEnable() == true){
    		Log.Warning("M_Search stoped");
    		Sockets.close();
    		looping_call.Stop();
    	}else
    		Log.Warning(msg_already_stopped);
    }
 public static void Break(){
	 if(isEnable() == true){
	   Stop();
	   
	 }
 }
}
